import { Component, Input, Output, EventEmitter, OnInit } from "@angular/core";
import { NzNotificationService } from "ng-zorro-antd";
import { Router, ActivatedRoute } from "@angular/router";
import { HttpServcie } from "../../../../service/http.service";
import { CommFuntion } from "../../../../service/commFunction";
import { Config } from "../../../../service/config";
import { el } from "@angular/platform-browser/testing/src/browser_util";
import {
  FormBuilder,
  FormGroup,
  Validators,
  FormControl
} from "@angular/forms";
import { InspectionRecord } from "../bean/inspection-record.bean";
import { FileUploader, FileItem, ParsedResponseHeaders } from "ng2-file-upload";
import { Observable } from "rxjs/Rx";
import { NzModalService, NzModalSubject } from "ng-zorro-antd";

@Component({
  selector: "inspection-detail",
  templateUrl: "inspection-detail.html",
  styleUrls: ["inspection-detail.scss"]
})
//电梯维修记录详情页
export class InspectionDetailPage implements OnInit {
  item: any;
  list: any = [{}]; //返回的数据
  validateForm: FormGroup;
  isSpinning: boolean = false;
  functions: any = [];
  expandDataCache = {};
  inValue: any = {};
  showBean: any = {};
  picList = [];
  data = [];
  @Output("outPut")
  outPut = new EventEmitter();
  config: any = Config;
  //接收参数
  inspectionBean: InspectionRecord = new InspectionRecord();
  constructor(
    private fb: FormBuilder,
    private httpServcie: HttpServcie,
    private router: Router,
    private _notification: NzNotificationService,
    private activatedRoute: ActivatedRoute,
    private commFuntion: CommFuntion,
    private currentModal: NzModalSubject,
    private modalService: NzModalService
  ) {
    this.activatedRoute.params.subscribe(data => {
      //深度 clone 一下，否则不能修改
      this.inValue = Object.assign({}, data);
    });
  }
  ngOnInit() {
    this.validateForm = this.fb.group({
      elevatorId: [null, [Validators.required]],
      checkUserId: [null, [Validators.required]],
      isUnusual: [null, [Validators.required]],
      checkStartDt: [null, [Validators.required]],
      checkEndDt: [null, [Validators.required]],
      signPicUrl: [null, [Validators.required]],
      inspectionSummary: [null, [Validators.required]],
      remarks: [null, [Validators.required]],
      other: [null, [Validators.required]],
      instructionsClear: [null, [Validators.required]],
      carInteriorLighting: [null, [Validators.required]],
      emergencyLighting: [null, [Validators.required]],
      emergencyAlarmDevice: [null, [Validators.required]],
      doorClipHolder: [null, [Validators.required]],
      switchDoorFlexible: [null, [Validators.required]],
      runningWithoutException: [null, [Validators.required]],
      operationLevelNormal: [null, [Validators.required]],
      layerButtonNormal: [null, [Validators.required]],
      callButtonNormal: [null, [Validators.required]],
      floorMonitorNormal: [null, [Validators.required]],
      staircaseLightNormal: [null, [Validators.required]],
      doorNoDeformation: [null, [Validators.required]],
      GateNoGap: [null, [Validators.required]],
      accessAndLighting: [null, [Validators.required]],
      distributionBoxLocked: [null, [Validators.required]],
      normalCall: [null, [Validators.required]],
      controllerNoDust: [null, [Validators.required]],
      contactorNoNoise: [null, [Validators.required]],
      machineNoEException: [null, [Validators.required]],
      emergencyProceduresClear: [null, [Validators.required]]
    });

    this.query();
  }
  //table加载数据时
  displayDataChange($event) {
    this.list = $event;
    this.refreshStatus();
  }
  //重置选择框
  refreshStatus() {}
  //交验
  getFormControl(name) {
    return this.validateForm.controls[name];
  }
  //点击返回按钮跳转主页面
  toBack() {
    window.history.back();
  }

  query() {
    this.httpServcie
      .getInspectionById({ id: this.inValue.id })
      .subscribe(data => {
        if (data.status == 200) {
          this.inspectionBean = data.data;
          this.showBean = this.commFuntion.convertBean(this.inspectionBean);
          console.log(this.inspectionBean);
        } else {
          this._notification.create("error", "查询失败，原因：", data.message);
        }
      });
  }

  showLargeImage(titlepic, contentpic, footerpic, img) {
    this.picList = [];
    this.picList.push(img);
    this.currentModal = this.modalService.open({
      title: titlepic,
      content: contentpic,
      footer: footerpic,
      maskClosable: false,
      width: 800,
      style: {
        top: "20px"
      },
      onOk() {
        console.log("Click ok");
      }
    });
  }
}
